package com.dk.service.impl;

import com.dk.mapper.TbBidrecordMapper;
import com.dk.pojo.TbBidrecord;
import com.dk.service.TbBidrecordService;
import com.dk.vo.TbBidrecordVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Service
public class TbBidrecordServiceImpl implements TbBidrecordService {

    @Resource
    private TbBidrecordMapper bidrecordMapper;

    @Override
    public List<TbBidrecordVO> selectPriceByCid(Long cid) {
        return bidrecordMapper.selectPriceByCid(cid);
    }

    @Override
    public TbBidrecordVO bid(Long userid, Long cid, Long money) {
        TbBidrecord bidrecord = new TbBidrecord();
        bidrecord.setUid(userid);
        bidrecord.setCid(cid);
        BigDecimal decimal = new BigDecimal(money);
        bidrecord.setPrice(decimal);
        bidrecord.setTiming(new Date());

        TbBidrecordVO bidrecordVO = new TbBidrecordVO();
        BeanUtils.copyProperties(bidrecord, bidrecordVO);
        bidrecordMapper.insert(bidrecord);
        return bidrecordVO;
    }

    @Override
    public TbBidrecordVO selectAllByBid(Long bid) {
        TbBidrecord bidrecord = bidrecordMapper.selectById(bid);
        TbBidrecordVO bidrecordVO = new TbBidrecordVO();
        BeanUtils.copyProperties(bidrecord, bidrecordVO);
        return bidrecordVO;
    }
}
